<%@ page pageEncoding="UTF-8"%>
<%@ include file="../common/global.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="../common/meta.jsp"%>
    <title><f:message key="common.title" /> - <f:message key="user.user_list" /> </title>
    <%@ include file="../common/css.jsp"%>
</head>
<body>
<div id="wrapper">
<%@ include file="../common/topbar.jsp"%>
<%@ include file="../common/header.jsp"%>

<div id="masthead">

    <div class="container">

        <div class="masthead-pad">
            <div class="masthead-pad">

                <div class="masthead-text">
                     <h5> <f:message key="user.user_list" /></h5>
                </div> <!-- /.masthead-text -->

            </div>
        </div>

    </div> <!-- /.container -->

</div> <!-- /#masthead -->

    <div id="content">

        <div class="container">

            <div class="row">

                <span class="span9">
                        <div id="user_list">
                            <%@ include file="list.jsp"%>
                        </div>
                </span><!--/.span9 -->

                <div class="span3">
                    <div class="well">
                    <form id="user_search_form" class="navbar-form navbar-left" >
                        <div class="form-group">
                            <input name="username" type="text" class="form-control ext-required" >
                        </div>
                        <br/>
                        <div class="form-group">
                            <button type="submit" class="btn">
                                <f:message key="common.search" />
                            </button>
                            <button type="button" id="create" class="btn btn-primary">
                                <f:message key="user.create_user"/>
                            </button>
                        </div>
                    </form>
                    </div>

                </div> <!-- /.span3 -->

            </div> <!-- /.row -->

        </div> <!-- /.container -->

    </div> <!-- /#content -->

</div> <!-- /#wrapper -->

<%@ include file="../common/footer.jsp"%>
<%@ include file="../common/js.jsp"%>
<script type="text/javascript">
    $(function() {
        $('#user_search_form').ajaxForm({
            type: 'post',
            url: BASE + '/users',
            dataType: 'html',
            success: function(html) {
                $('#user_list').html(html);
            }
        });

        $('.ext-user-delete').click(function() {
            var $tr = $(this).closest('tr');
            var username = $tr.data('username');
            if (confirm(Smart.i18n('user.delete_confirm', username))) {
                var url = $(this).attr('href');
                $.ajax({
                    type: 'delete',
                    url: url,
                    dataType: 'json',
                    success: function(result) {
                        if (result.success) {
                            location.reload();
                        }
                    }
                });
            }
            return false;
        });



        $('#create').click(function() {
            location.href = BASE + '/user';
        });

    });
</script>
</body>
</html>